//
//  MCAddFreightHeadView.swift
//  StoreManage
//
//  Created by MC on 2018/9/20.
//  Copyright © 2018年 MC. All rights reserved.
//

import UIKit

typealias MCAddFreightHeadViewClosure = () -> Void

class MCAddFreightHeadView: UIView {

    var closure : MCAddFreightHeadViewClosure?
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        self.addSubview(nameView)
        nameView.snp.remakeConstraints { (make) ->Void in
            make.left.equalTo(15)
            make.right.equalTo(-15)
            make.top.equalTo(0)
            make.height.equalTo(50)
        }
        

        
        
        
        
        self.addSubview(freightView)
        freightView.snp.remakeConstraints { (make) ->Void in
            make.left.equalTo(15)
            make.right.equalTo(-15)
            make.top.equalTo(nameView.snp.bottom).offset(0)
            make.height.equalTo(50)
        }
        
        self.addSubview(lineView)
        lineView.snp.remakeConstraints { (make) ->Void in
            make.left.right.equalTo(self)
            make.top.equalTo(freightView.snp.bottom)
            make.height.equalTo(7)
        }

      
        self.addSubview(areaLabel)
        areaLabel.snp.remakeConstraints { (make) ->Void in
            make.left.equalTo(15)
            make.right.equalTo(-15)
            make.top.equalTo(lineView.snp.bottom).offset(0)
            make.height.equalTo(50)
        }
        
        
        self.addSubview(editButton)
        editButton.snp.remakeConstraints { (make) ->Void in
            make.right.equalTo(-15)
            make.centerY.equalTo(areaLabel)
            make.width.height.equalTo(25)
        }

    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    @objc func editButtonEvent() {
        closure?()
    }
    
    lazy var nameView: MCInputBarView = {
        let view = MCInputBarView()
        view.leftLabel.text = "模板名称:"
        view.lineView.isHidden = false
        view.backgroundColor = UIColor.white
        return view
    }()
    
    lazy var freightView: MCInputBarView = {
        let view = MCInputBarView()
        view.leftLabel.text = "默认运费:"
        view.lineView.isHidden = false
        view.backgroundColor = UIColor.white
        view.rightTextField.rightShowText = "(元)"
        view.rightTextField.keyBoardType = MCKeyBorardType.decimal
        return view
    }()
    
    lazy var lineView: UIView = {
        let view = UIView()
        view.backgroundColor = UIColor.MCGray_light
        return view
    }()
    
    
    lazy var areaLabel: MCLabel = {
        let label = MCLabel()
        label.font = MCFont(16)
        label.text = "设置不配送区域:"
        label.layer.borderColor = UIColor.MCGray_light.cgColor
        label.layer.borderWidth = 1
        label.backgroundColor = UIColor.white
        return label
    }()
    
    lazy var editButton: UIButton = {
        let button = UIButton.init(type: UIButtonType.custom)
        button.setImage(#imageLiteral(resourceName: "GoodsManage_add"), for: .normal)
        button.contentHorizontalAlignment = UIControlContentHorizontalAlignment.right
        button.addTarget(self, action: #selector(editButtonEvent), for: .touchUpInside)
        return button
    }()
}
